Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

falsey

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

falsey

Returns true if `value` is falsey. Works for strings, arrays and `arguments` objects with a length of `0`, and objects with no own enumerable properties are considered falsey.

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
121K
decreased by-11.99%
Maintainers
2
Weekly downloads
 
Created
Source

falsey NPM version NPM monthly downloads NPM total downloads Linux Build Status Windows Build Status

Returns true if value is falsey. Works for strings, arrays and arguments objects with a length of 0, and objects with no own enumerable properties are considered falsey.

Install

Install with npm:

$ npm install --save falsey

What makes this lib unique (and fun) is the option to pass an array of values that should always evuate as "falsey".

This is useful for CLI prompts, web forms, etc. For example, you might want to allow users to define nil or nope to disable something.

Usage

var isFalsey = require('falsey');

console.log(isFalsey('nil');
//=> `true`

Examples

All of the following return true

isFalsey(undefined);
isFalsey(null);
isFalsey(false);
isFalsey(0);
isFalsey('');
isFalsey(NaN);
isFalsey({});
isFalsey([]);

All of the following return false:

isFalsey('foo');
isFalsey(true);
isFalsey(50);
isFalsey('10');
isFalsey({a: 'b'});
isFalsey([0]);

Special cases

There are several additional "falsey" words built in, but these can be overridden or turned off by passing a value as the second argument.

Built-in additional falsey keywords

  • none
  • nil
  • nope
  • no
  • nada
  • 0
  • false

Disable additions

isFalsey('nil', []);
//=> false

Customize additions

Pass one or more keywords that should return true when evaluated as falsey:

isFalsey('zilch', ['no', 'nope', 'nada', 'zilch']);
//=> true

Extend additions

Built-in keywords are exposed on the .keywords property. These can be used to extend the defaults:

isFalsey('zilch', isFalsey.keywords.concat(['zilch']));
//=> true

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on September 11, 2017.

Keywords

FAQs

Package last updated on 11 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc